<?php
include_once('./config/config.php');
$depSql = "select * from `pre_department`";
$depData = all($depSql);
// 获取管理员id
$id = $_GET['id'];
// 查询该id的用户名
$sql = "select j.*, d.name as dname from `pre_job` as j left join `pre_department` as d on j.dep_id = d.id where j.id= '$id'";
// 执行
$Job = find($sql);

if ($_POST) {
  $name=$_POST['name'];
  $dep_id=$_POST['depid'];
  // 用于封装数据
  $data=[];
  if(!empty($name)){
    $data['name']=$name;
  }
  if(!empty($dep_id)){
    $data['dep_id']=$dep_id;
  }
  $result = update('job', $data, "`id` = '$id'");
  // 判断是否修改成功
  if ($result['code'] === 1) {
    ShowMsg($result['msg'], 'JobList.php');
  } else {
    echo $result['msg'];
    exit;
  }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <!-- 引入公共样式 -->
  <?php include_once('./common/meta.php'); ?>

  <!-- 引入公共js -->
  <?php include_once('./common/script.php'); ?>
</head>

<body>
  <!-- 引入头部 -->
  <?php include_once('./common/header.php'); ?>

  <!-- 引入侧边菜单 -->
  <?php include_once('./common/menu.php'); ?>

  <div class="content">
    <div class="header">
      <h1 class="page-title">编辑职位</h1>
    </div>
    <ul class="breadcrumb">
      <li><a href="index.php">Home</a> <span class="divider">/</span></li>
      <li class="active">Index</li>
    </ul>

    <div class="container-fluid">
      <div class="row-fluid">

        <div class="btn-toolbar">
          <button class="btn btn-primary" onClick="location='JobList.php'"><i class="icon-list"></i> 职位列表</button>
          <div class="btn-group">
          </div>
        </div>

        <div class="well">
          <div id="myTabContent" class="tab-content">
            <div class="tab-pane active in" id="home">
              <form method="post" enctype="multipart/form-data">
                <label>职位名称</label>
                <input type="text" name="name" id="name" class="input-xxlarge" value="<?php echo $Job['name'] ?>">
                <label>所属部门</label>
                <select name="depid" class="input-xlarge">
                  <option value="<?php echo $Job['dep_id']; ?>"><?php echo $Job['dname']; ?></option>
                  <?php foreach ($depData as $item) { ?>
                    <option value="<?php echo $item['id']; ?>"><?php echo $item['name']; ?></option>
                  <?php } ?>
                </select><br />
                <input class="btn btn-primary" type="submit" value="修改" />
              </form>
            </div>
          </div>
        </div>

        <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Delete Confirmation</h3>
          </div>
          <div class="modal-body">

            <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?
            </p>
          </div>
          <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <button class="btn btn-danger" data-dismiss="modal">Delete</button>
          </div>
        </div>

        <!-- 引入底部 -->
        <?php include_once('./common/footer.php'); ?>
      </div>
    </div>
  </div>

</body>

</html>

<!-- <script>
  $('#name').change(function() {
    var name = $(this).val();
    $.ajax({
      type: "POST",
      url: 'proces.php',
      data: {
        action: 'Jobselect',
        name,
      },
      dataType: 'json',
      success: function(data) {
        if (data.code === 1) {
          layer.msg(data.msg);
        }
      }
    })
  })
</script> -->